package com.notecalendar.ws;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.evernote.edam.notestore.NoteList;
import com.evernote.edam.type.Note;
import com.notecalendar.EvernoteBean;
import com.notecalendar.exception.EvernoteBeanException;


@Controller
@RequestMapping("/ntcs")
public class NoteCalendarService {
	
	//Injected via Spring
	private EvernoteBean evernoteBean;
	public void setEvernoteBean(EvernoteBean evernoteBean) {
		this.evernoteBean = evernoteBean;
	}
	
	
	private static final String VIEW_NOTELIST = "ntcsNoteListResponse";
	
	

	@RequestMapping(method=RequestMethod.POST, value="/noteList")
	public ModelAndView postNoteList(@RequestParam String authContext,@RequestParam String shardId){
		System.out.print("NoteCalendarService.postNoteList-->");
		System.out.print(" AuthContext:"+authContext);
		System.out.println(" shardId:"+shardId);
		NoteList noteList = new NoteList();
		List<Note> nList = new ArrayList<Note>();
		try {
			noteList = evernoteBean.getNotes(shardId,authContext);
			nList = noteList.getNotes();
			System.out.println("NoteList:"+nList.size());
		} catch (EvernoteBeanException e) {
			e.printStackTrace();
		}
		
		return new ModelAndView(VIEW_NOTELIST, "notelist", nList);
	}
	
	
}
